package com.xxzb.pack0823.线程同步.协作同步;

public class Test {
    public static void main(String[] args) {
        //创建面包柜对象
        final BreadContainer breadContainer = new BreadContainer(10);
        //创建面包师傅1线程(生产者)
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    Bread bread = new Bread(i);
                    breadContainer.addBread(bread);
                }
            }
        }, "面包师傅1").start();
        //创建面包师傅2线程(生产者)
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    Bread bread = new Bread(i);
                    breadContainer.addBread(bread);
                }
            }
        }, "面包师傅2").start();

        //创建销售员1线程(消费者)
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    breadContainer.getBread();
                }
            }
        },"销售员1").start();
        //创建销售员2线程(消费者)
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    breadContainer.getBread();
                }
            }
        },"销售员2").start();

    }
}
